import { phoneRegex, emailRegex } from '@/utils/regex';
import { check, isError } from '@/utils/verification';
import { IRegister } from '@/types/register';
import { Ref } from 'vue';

/**
 * 注册第一个页面验证
 * @param register 
 */
export function checkMain1(register: IRegister, step: Ref<number>) {

  if (check(phoneRegex, register.phone, "手机号不正确") &&
    check(/^\d{4}$/, register.code, "验证码不能是数字以外的值") &&
    check(emailRegex, register.email, "邮箱格式不正确") &&
    check(/^\w{6,19}$/, register.password, "密码格式不正确6-19位")) {

    step.value++;
  }
}

/**
 *  注册第二个页面验证
 * @param register 
 * @param step 第几步
 */
export function checkMain2(register: IRegister, step: Ref<number>) {
  if (isError(register.work.length > 0, "职业不能为空") &&
    isError(register.desc.length > 0, "描述不能为空")) {
    step.value++;
  }
}

/**
 *  注册第三个页面验证
 * @param register 
 * @param step 
 */
export function checkMain3(register: IRegister, step: Ref<number>) {
  if (check(/^\w{6,20}/, register.company.name, "公司名称不正确") &&
    isError(register.company.direction.length > 0, "业务方向不能为空") &&
    isError(register.company.size > 0 && register.company.size <= 500, "公司人数不能小于0或")
  ) {
    step.value++;
  }
}

